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.
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 likevendor_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 likevendor_id
,dispatch_location_id
,early_date
,late_date
,driver_load
,form_ids
,number
,status
, andtype
. -
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 intmpRouteObject
. -
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
Replace <Access token> with your Motive API access token and <body> with the constructed JSON body from the previous step.
API Response
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.
Motive Dashboard: Track the dispatch details in the Motive Dashboard to monitor the status and progress of each route.
The status can be tracked on both mobile app and web app interface.
Completion Summary: Upon dispatch completion, Motive will generate a short summary, providing an overview of the completed tasks and any issues encountered.
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.