Order Grouping

NextBillion.ai’s Route Optimization Flexible API offers a simple but useful feature, called order grouping, that enhances the driver experience by conveniently planning a common stop for multiple tasks located closeby. Users can configure a diameter which will be used to group all tasks falling within the given range and treat them as a single stop. For scenarios involving multiple tasks in a condo, or in a building, or a housing complex, users can utilize this feature to resolve all such locations to a single stop saving time and driver’s effort to park the vehicle at multiple stops. Let’s build an example to implement this feature


We have a total of 5 delivery jobs out of which 3 are located quite close to each other. We will use a single vehicle to fulfill all these deliveries. Locations We will start by adding all the locations used in the problem along with a valid id. The locations object with all the coordinates used in this example:

2 "locations":"{...}",


Next we define 5 delivery jobs by specifying:

  • A unique identifier for each task
  • Location indexes for each task
  • Delivery quantities for each task
  • Service time for each task

Let’s take a look at the jobs JSON after the above properties are configured:

2 "jobs":"[...]",


Next, we add the details of the vehicles that will be responsible for fulfilling the tasks. We configure:

  • A unique ID
  • Vehicle’s capacity
  • Start_index to denote the point from where the vehicle would start.

Following is the vehicle JSON that is used:

1"vehicles": [
2 {
3 "id": 1,
4 "start_index": 5,
5 "capacity": [
6 25
7 ]
8 }
9 ]


And lastly, we configure the criteria to group the tasks that are close by. For our example, we specify a diameter of 200 meters to group any tasks located close to each other :

2 "grouping":{
3 "order_grouping":{
4 "grouping_diameter":200
5 }
6 }
7 }

Optimization POST Request

Now let’s put all these components together and create the final POST request that we will submit to the optimizer.

1curl --location 'https://api.nextbillion.io/optimization/v2?key=<your_api_key>' --header 'Content-Type: application/json' --data '{...}'

Optimization POST Response

Once the request is made, we get a unique ID in the API response:

2"id": "27c6d7912589e1153b62867ccdae031d",
3"message": "Optimization job created",
4"status": "Ok"

Optimization GET Request

We take the ID and use the Optimization GET request to retrieve the result. Here is the GET request:

1curl --location 'https://api.nextbillion.io/optimization/v2/result?id=27c6d7912589e1153b62867ccdae031d

Optimization GET Response

Following is the optimized route plan:

2 "result": {
3 "code": 0,
4 "summary": "{...}",
5 "unassigned": "[...]",
6 "routes": "[...]"
7 },
8 "status": "Ok",
9 "message": ""

Following image shows a visual representation of the above route plan.


Analyzing the Solution

Looking at the result we observe that:

  • All the tasks were successfully assigned with a total travel cost of 1410
  • The 3 delivery tasks, Delivery 1, 2 & 3, located close to each other were treated as a single stop. The location of the common stop was returned by the field projected_location in the solution.

This example exhibits how NextBillion.ai’s Route Optimization Flexible API can be used to group nearby tasks to save time, get efficient route plans and deliver a good driver experience. Readers can go ahead and try out different configurations of grouping criteria and task locations or just remove the grouping constraint and compare travel costs to explore how the solution changes under different scenarios presented to Route Optimization Flexible API.

Learn more about the other powerful features and the related use cases that Route Optimization Flexible API can solve for you.