none
Multi-Itinerary Optimization API RRS feed

  • Question

  • Hi,

    I need to know more details regarding Multi-Itinerary Optimization API.

    Let say, I have a sales person who works from 8.00 am to 5.00 pm with lunch break of 1 hours between 1.00 pm to 2.00 pm. And have 15 jobs to visit. And i want to generate optimize route for this sales person. So as per MIO API blog, sales persons shift will be divided in 2 part as 8.00 am - 1.00 pm and from 2.00 pm - 5.00 pm. But, MIO API is also expecting the location of 1.00 pm which is end of 1st shift and 2.00 pm which is start of another shift. As i have to schedule these 15 jobs dynamically, then how do we know the end location of 1<sup>st</sup> shift i.e. location at 1.00 pm and start location of 2nd shift i.e. location at 2.00 pm. I was expecting that the end location of 1st shift and start location of 2nd shift should be set/considered dynamically.

    Also, MIO API generate routes for each agents/sales person, but it is providing only Latitude and Longitude to visit next, not the name or index of the Itinerary to visit. 

    So is there any way to add Names of client in this generated routes for the sales person in API, so that it will be easier for me to check that, from start location, sales person need to go to record X and from records X, he need to go to record Y.  

    Thank You!

    Friday, May 10, 2019 6:17 AM

All replies

  • Hi Yogesh, 

    Thanks for your interest in the MIO API. With one agent and multiple shifts, the start and end locations of each shift are optional. Below is an example how you can define the shifts: 

    {
     "agents": [{
       "name": "Salesperson",
       "shifts": [{
         "startTime": "2019-05-10T08:00:00",
         "startLocation": {
          "latitude": 47.60897,
          "longitude": -122.340914
         },
         "endTime": "2019-05-10T13:00:00"
         
         
        }, {
         "startTime": "2019-05-10T14:00:00",
         
         "endTime": "2019-05-10T17:00:00",
         "endLocation": {
          "latitude": 47.739236,
          "longitude": -122.339974
         }
        }
       ]
      }
     ],
     "itineraryItems": [{
       "name": "Café Twelfth",
       "openingTime": "2019-01-24T08:00:00",
       "closingTime": "2019-01-24T20:00:00",
       "dwellTime": "01:30:00.00",
       "priority": 1,
       "location": {
        "latitude": 47.615006,
        "longitude": -122.348236
       }
      }, {
       "name": "Granny Food Truck",
       "openingTime": "2019-01-24T11:00:00",
       "closingTime": "2019-01-24T14:30:00",
       "dwellTime": "01:30:00.00",
       "priority": 1,
       "location": {
        "latitude": 47.664440,
        "longitude": -122.372138
       }


    The API output now includes the itinerary item names. 

    Thank you!


    • Proposed as answer by Ashley Song Friday, May 17, 2019 8:33 PM
    • Edited by Ashley Song Friday, May 17, 2019 8:33 PM
    Friday, May 10, 2019 4:32 PM
  • Hi Ashley,

    Thanks for your reply.

    I have tried that too, but, it gives me error as below : 

    {"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2019 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","errorDetails":["Your request could not be completed because there was a problem with the service."],"resourceSets":[],"statusCode":500,"statusDescription":"Internal Server Error","traceId":""}.

    But when i put Start and End location for both the shifts then its shows me proper data as below:

    {"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2019 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":1,"resources":[{"__type":"OptimizeItinerary:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","agentItineraries":[{"agent":{"name":"Salesperson","shifts":[{"endLocation":{"latitude":47.639236,"longitude":-122.339974},"endTime":"2019-05-10T13:00:00","startLocation":{"latitude":47.60897,"longitude":-122.340914},"startTime":"2019-05-10T08:00:00"},{"endLocation":{"latitude":47.739236,"longitude":-122.339974},"endTime":"2019-05-10T17:00:00","startLocation":{"latitude":47.639236,"longitude":-122.339974},"startTime":"2019-05-10T14:00:00"}]},"instructions":[{"instructionType":"LeaveFromStartPoint","itineraryItem":{"location":{"latitude":47.60897,"longitude":-122.340914},"priority":1},"startTime":"2019-05-10T08:00:00"},{"distance":4242,"duration":"00:10:00","endTime":"2019-05-10T08:10:00","instructionType":"TravelBetweenLocations","startTime":"2019-05-10T08:00:00"},{"instructionType":"ArriveToEndPoint","itineraryItem":{"location":{"latitude":47.639236,"longitude":-122.339974},"priority":1},"startTime":"2019-05-10T08:10:00"},{"instructionType":"LeaveFromStartPoint","itineraryItem":{"location":{"latitude":47.639236,"longitude":-122.339974},"priority":1},"startTime":"2019-05-10T14:00:00"},{"distance":17170,"duration":"00:19:00","endTime":"2019-05-10T14:19:00","instructionType":"TravelBetweenLocations","startTime":"2019-05-10T14:00:00"},{"instructionType":"ArriveToEndPoint","itineraryItem":{"location":{"latitude":47.739236,"longitude":-122.339974},"priority":1},"startTime":"2019-05-10T14:19:00"}],"route":{"endLocation":{"latitude":47.739236,"longitude":-122.339974},"endTime":"2019-05-10T14:19:00","startLocation":{"latitude":47.60897,"longitude":-122.340914},"startTime":"2019-05-10T08:00:00","totalTravelDistance":21412,"totalTravelTime":"00:29:00","wayPoints":[{"latitude":47.639236,"longitude":-122.339974},{"latitude":47.639236,"longitude":-122.339974}]}}],"isAccepted":true,"isCompleted":true}]}],"statusCode":200,"statusDescription":"OK","traceId":""}

    Below is the code which i am using, taking your example : 

     var request = {
            "agents": [{
                "name": "Salesperson",
                "shifts": [{
                    "startTime": "2019-05-10T08:00:00",
                    "startLocation": {
                        "latitude": 47.60897,
                        "longitude": -122.340914
                    },
                    "endTime": "2019-05-10T13:00:00"//,
                     //"endLocation": {
                       //"latitude": 47.639236,
                         //"longitude": -122.339974
                    }
                },
                {
                    "startTime": "2019-05-10T14:00:00",
                     //"startLocation": {
                       //"latitude": 47.639236,
                        // "longitude": -122.339974
                     //},
                    "endTime": "2019-05-10T17:00:00",
                    "endLocation": {
                        "latitude": 47.739236,
                        "longitude": -122.339974
                    }
                }
                ]
            }
            ],
            "itineraryItems": [{
                "name": "Café Twelfth",
                "openingTime": "2019-01-24T08:00:00",
                "closingTime": "2019-01-24T20:00:00",
                "dwellTime": "01:30:00.00",
                "priority": 1,
                "location": {
                    "latitude": 47.615006,
                    "longitude": -122.348236
                }
            },
            {
                "name": "Granny Food Truck",
                "openingTime": "2019-01-24T11:00:00",
                "closingTime": "2019-01-24T14:30:00",
                "dwellTime": "01:30:00.00",
                "priority": 1,
                "location": {
                    "latitude": 47.664440,
                    "longitude": -122.372138
                }
            }
            ]
        };

        $.ajax({
            url: "https://dev.virtualearth.net/REST/V1/Routes/OptimizeItineraryAsync?key={bing key}",
            type: "Post",
            data: JSON.stringify(request),
            datatype: "json",
            contentType: "application/json",
            success: function (result) {
                window.open(result.resourceSets[0].resources[0].callbackUrl,"_blank");
            },
            error: function (response) {
                alert("error ");
            }

        });

    I need to implement this for multiple users as well.

    Thank you!



    Monday, May 13, 2019 8:54 AM
  • Hi Yogesh,

    The team is reviewing your code and thinks they have a fix. I expect it will need to go through test and deployment steps so hopefully will be available soon.

    Sincerely,

    IoTGirl

    Monday, May 13, 2019 3:53 PM
    Owner
  • Hi Yogesh, 

    The braces in your code did not match up. Please try the following example which excludes the end location of first shift and start location of the 2nd shift. Also, please check the output again. We have added the place name for each item in the output. 

    {   "agents": [{
                "name": "Salesperson",
                "shifts": [{
                    "startTime": "2019-05-10T08:00:00",
                    "startLocation": {
                        "latitude": 47.60897,
                        "longitude": -122.340914
                    },
                    "endTime": "2019-05-10T13:00:00"
                },
                {
                    "startTime": "2019-05-10T14:00:00",
                    "endTime": "2019-05-10T17:00:00",
                    "endLocation": {
                        "latitude": 47.739236,
                        "longitude": -122.339974
                    }
                }
              ]
      }
     ],
            "itineraryItems": [{
                "name": "Café Twelfth",
                "openingTime": "2019-01-24T08:00:00",
                "closingTime": "2019-01-24T20:00:00",
                "dwellTime": "01:30:00.00",
                "priority": 1,
                "location": {
                    "latitude": 47.615006,
                    "longitude": -122.348236
                }
            },
            {
                "name": "Granny Food Truck",
                "openingTime": "2019-01-24T11:00:00",
                "closingTime": "2019-01-24T14:30:00",
                "dwellTime": "01:30:00.00",
                "priority": 1,
                "location": {
                    "latitude": 47.664440,
                    "longitude": -122.372138
                }
            }
        ]
    }

    Thanks,
    Ashley

     
    • Proposed as answer by Ashley Song Friday, May 17, 2019 8:33 PM
    Friday, May 17, 2019 8:24 PM