Transportation Cost Optimization

In the world of logistics and transportation, managing costs is as critical as ensuring timely deliveries. With rising fuel prices, vehicle maintenance expenses, licensing fees, and a host of other varieties of costs, effective cost optimization becomes absolutely critical. This guide explores the transportation cost management features that NextBillion.ai Route Optimization API offers to emulate real-world business constraints. For each vehicle used in the planning process, users can configure all or any combination of fixed, per_hour, per_km and per_order costs. Once specified, the routes with lower costs are preferred over others, in general, subject to other constraints like - time_windows, location of the tasks etc.

The transportation cost management functions of Route Optimization API aid users in

  1. Minimizing overall transportation costs
  2. Analyze actual costs incurred to identify favourable third party logistics providers

Let’s explore how transportation cost optimization comes into play when applied to a real-world route optimization problem.

Setup

We have a total of 3 pickup jobs and a couple of shipments to be fulfilled. We use a total of 3 vans, which starts from a designated warehouse location and brings the items collected from the pickup locations back to the depot. To highlight the impact of transportation costs on the final solution, we provide multiple combinations of different cost types for each vehicle. Let’s configure the locations, tasks, and the vehicles along with their costs one by one in the following sections.

Locations

We will start with adding the locations used in the problem along with a valid id. The locations object with all the points used in this example:

1
"locations": {
2
"id": 11,
3
"location": [
4
"34.083950,-118.318640",
5
"34.076350,-118.338519",
6
"34.000895,-118.204929",
7
"34.018780,-118.317919",
8
"33.996658,-118.261708",
9
"33.916595,-118.240132",
10
"33.946275,-118.385486",
11
"34.02316039722285,-118.46149125160315"
12
]
13
}

Jobs & Shipments

Next we define 3 pickup jobs and 2 shipments. For each these tasks we configure:

  • A unique identifier
  • A Location index
  • Specify the schedule of tasks using the time_windows
  • A service time

Following is the completely built JSON with the desired configurations for the jobs and shipments:

1
{
2
"jobs": "[...]",
3
"shipments": "[...]",
4
}

Vehicles

Next, we add the 3 vans that are going to fulfill the tasks along with their cost components. To configure each of these vans and their properties we specify:

  • A unique ID
  • A shift time or the time window
  • Capacity to denote the amount of load that the van can take
  • Start_index and end_indexes to denote the start and end points for a van.
  • Skills of the driver or the van
  • In order to demonstrate the impact of each type of transportation costs, let’s add
    • Van 1: A per_hour cost
    • Van 2: A per_order cost.
    • Van 3: A fixed cost.

Once the vehicle and their properties are defined, the resulting vehicles JSON is:

1
"vehicles": [
2
{
3
"id": "Vehicle 1",
4
"start_index": 7,
5
"capacity": [
6
50
7
],
8
"costs": {
9
"per_hour": 1000
10
},
11
"time_window": [
12
1693396800,
13
1693404000
14
]
15
},
16
{
17
"id": "Vehicle 2",
18
"start_index": 7,
19
"capacity": [
20
50
21
],
22
"costs": {
23
"per_order": 800
24
},
25
"time_window": [
26
1693402200,
27
1693411200
28
]
29
},
30
{
31
"id": "Vehicle 3",
32
"start_index": 7,
33
"capacity": [
34
50
35
],
36
"costs": {
37
"fixed": 2500
38
},
39
"time_window": [
40
1693402200,
41
1693413000
42
]
43
}
44
]

Optimization POST Request

Bringing all these components together to create the final POST request that we will submit to the optimizer.

1
curl --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:

1
{
2
"id": "abf22b1aac3334e8d3908712e2056580",
3
"message": "Optimization job created",
4
"status": "Ok"
5
}

Optimization GET Request

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

1
curl --location curl --location 'https://api.nextbillion.io/optimization/v2/result?id=abf22b1aac3334e8d3908712e2056580&key=<your_api_key>'

Optimization GET Response

Following is the optimized route plan:

1
{
2
"description": "Transportation Cost Optimization Example",
3
"result": "{...}",
4
"status": "Ok",
5
"message": ""
6
}

Following is a visual representation of the initial locations of tasks, vehicles and the routes suggested after optimization as per the given constraints.

Sample route plan when different transportation costs are in play

Route Plan to optimize transportation cost

Analyzing the Solution

Looking at the result we can observe some interesting insights:

  • As we know from the Basic Route Optimization example that the cost value is returned as per the travel_cost set in the input request. In our example, the cost is calculated based on the duration. Let’s take a look at the costs for each vehicle:
    • Vehicle 1: This van’s incurs costs per_hour at the configured rate of 1000 per hour. In the solution, this vehicle is assigned to a route that takes around half an hour to complete (~1819 seconds). Hence, the overall cost for this van, and effectively for the route, comes out to be 505.
    • Vehicle 2: This vehicle was configured to incur cost for each order that it completes at a rate of 800 per order. In the solution, this vehicle fulfills only 1 order (Shipment 2) and hence the cost of 1 order is added to the overall duration of 2715 seconds that it takes to complete the route, leading to an overall cost of 3515.
    • Vehicle 3: This vehicle was configured with a fixed cost of 2500. So the overall duration for this route, 2527 seconds, was added to the fixed cost to give a final route cost of 5027.

As we saw, NextBillion.ai’s Route Optimization API understands the cost considerations you provide and suggests the best solution accordingly. We encourage you to go ahead and try out different configurations of vehicle or task locations, time window constraints, number of tasks and explore how different solutions are generated for different scenarios presented to Route Optimization API.

We hope this example was helpful. Check out more tutorials & use cases that Route Optimization API can handle for you!

© 2025 NextBillion.ai all rights reserved.