Dynamically Route New E-Commerce Orders
See files for this Use Case on GitHub here
With Route4Me, you can dynamically route new e-commerce orders on the fly.
The main difference between an address and an order is the fact that an order isn't attached to a permanent customer in your Route4Me account, while an address is.
If you have many new orders per day, you can upload them directly into our planner by browsing for a CSV file - which is simply a type of file (.csv) you can choose after you press "Save As" on Microsoft Excel (you can see a sample of a csv file here)
Of course, you can use other input formats too, including JSON file, Access DB, SQLite, MySql, Sql, etc. For simplicity's sake, we'll only be reviewing JSON and CSV options.
Create an Optimization
The cURL example below shows you how to create new optimized routes for this Use Case:
- the endpoint for this task is https://www.route4me.com/api.v4/optimization_problem.php
- input data is stored in the file create_new_optimization_data.json
|api_key||string||API KEY of the user|
|input data||POST data||Valid JSON object string. Click here to see the JSON Schema|
You can expect an Optimization Problem (see link), which has generated some routes already. On Route4Me's map, you can see this as:
Review the orders to be added
Suppose you received new orders from customers to deliver cargo (see link for input data). On the map, these orders could be located as:
- The sample data on our GitHub repository is not constant. They belong to a demo account, which is used by many users for testing, so data changes regularly. For accurate testing of our API examples, you'll need to enter up-to-date information yourself.
The Optimization Problem is a set of addresses with parameters for generating optimal routes. You can view them in the sample mentioned above.
As for an order's input JSON data, there is one depot (without order ID) and 3 addresses (with order IDs) and parameters for route-generating options. This data should be sent as HTTP POST data.
Add orders to an Optimization
Apart from the POST data with orders, you should also send some parameters with the HTTP GET method:
- api_key - put the API key you obtained from Route4Me here;
- optimization_problem_id - put the ID of the Optimization Problem to which will be added new orders here;
- redirect - this should be 0 in our case.
|api_key||string||API KEY of the user||GET|
|optimization_problem_id||string||Optimization Problem ID||GET|
|redirect||integer||If equal to 1, will be redirected, if 0 - not||GET|
|parameters||Route Parameters||Valid JSON object string. Click here to see the JSON Schema||POST|
|addresses||array||Valid JSON string of Address object array. lick here to see the JSON Schema||POST|
See sample RESPONSE JSON data here
Table of the Response parameters
|optimization_problem_id||string||Optimization Problem ID|
|state||integer||Optimization problem state|
|created_timestamp||integer||A creation time of an Optimization Problem|
|scheduled_for||integer||Date order was scheduled for|
|optimization_completed_timestamp||integer||Optimization completion date|
|parameters||Route Parameters||Valid JSON object string. Click here to see the JSON Schema|
|addresses||array||Valid JSON string of Address object array. lick here to see the JSON Schema|
|routes||array||Valid JSON string of Route object array. lick here to see the JSON Schema|
|links||array||Valid JSON string of Link object array. lick here to see the JSON Schema|
You can view this result on Route4Me's map as: