Dispatch Optimized Routes to Motive

After generating the optimized routes with NextBillion.ai's API, the next step is to dispatch these routes to the Motive Driver App. Here's how to do it:

Step 1: Construct and Dispatch Routes

Construct the POST Request Body: Use the optimized routes data to create a request body suitable for the Motive API.

Refer to Motive API documentation for more information.

Dispatch Routes: Use the following JavaScript code to construct and dispatch routes.

1
// Initialize an array to store all routes
2
3
let allRoutes = [];
4
5
// Iterate over the routes and construct route objects
6
nbaiOptimizationStatus.data.result.routes.forEach(rte => {
7
let route = {
8
"vendor_id": `AMZN-${uuid.v4().split('-')[0]}`,
9
"vehicle_id": 1535464,
10
"shipper_dispatch_location_id": 1554007,
11
"consignee_dispatch_location_id": 1554007,
12
"consignee_status": "available",
13
};
14
})

Code Explanation

This code initializes an array to store routes, iterates over the optimized routes to construct route objects, assigns driver IDs, constructs stop objects for each route, adds the routes to the array, converts the array to a JSON string, and finally makes POST requests to the Motive API for each route.

A detailed description of the code is as follows:

  • An empty array called allRoutes is initialized which will store all the constructed route objects.

  • For each route in the nbaiOptimizationStatus.data.result.routes array, a new route object is created with various attributes like vendor_id, vehicle_id, shipper_dispatch_location_id, etc.

  • The driver ID is assigned based on the vehicle ID from the route object. This ensures that each vehicle is assigned the correct driver.

  • For each stop in the route’s steps, a stop object is created and added to the dispatch_stops array in the route object. The stop object includes attributes like vendor_id, dispatch_location_id, early_date, late_date, driver_load, form_ids, number, status, and type.

  • The constructed route object is added to the allRoutes array.

  • The allRoutes array is converted to a JSON string for the API request. It is also logged to the console for debugging purposes and stored in tmpRouteObject.

  • For each route in the allRoutes array, a POST request is made to the Motive API. The success and failure callbacks log the response to the console.

Step 2: POST Dispatches to Motive

Use the following cURL command to dispatch the routes to the Motive API.

API Request

1
curl --location 'https://api.keeptruckin.com/v1/dispatches' \
2
--header 'Authorization: Bearer <Access token>' \
3
--data '<body>'

Replace <Access token> with your Motive API access token and <body> with the constructed JSON body from the previous step.

API Response

1
{
2
"dispatch": {
3
"id": 6640255,
4
"driver_id": 4764848,
5
"vehicle_id": 1535464,
6
"consignee_dispatch_location_id": 1554007,
7
"shipper_dispatch_location_id": 1554007,
8
}
9
}

Step 3: Track and Manage Dispatches

Driver App Updates: The generated routes will be dispatched to the respective drivers' apps. Drivers must update arrival and departure information in the app, which will be used for tracking.

documentation image

Motive Dashboard: Track the dispatch details in the Motive Dashboard to monitor the status and progress of each route.

documentation image

The status can be tracked on both mobile app and web app interface.

documentation image

Completion Summary: Upon dispatch completion, Motive will generate a short summary, providing an overview of the completed tasks and any issues encountered.

documentation image

This integration streamlines the process of route planning and management, reducing operational costs, improving service times, and maximizing resource utilization.

For any further assistance or advanced customization, refer to the respective API documentation of Motive and NextBillion.ai, or reach out to the support team.

© 2024 NextBillion.ai all rights reserved.