コード例 #1
0
        private void ImportRequestBtn_Clicked(object sender, RoutedEventArgs e)
        {
            //Load a request from a JSON file.
            var ofd = new OpenFileDialog();

            ofd.Filter           = "JSON files (*.json)|*.json|All files (*.*)|*.*";
            ofd.RestoreDirectory = true;

            var dl = ofd.ShowDialog();

            if (dl.HasValue && dl.Value)
            {
                using (var fs = ofd.OpenFile())
                {
                    try
                    {
                        request = requestSerializer.ReadObject(fs) as OptimizeItineraryRequest;
                        LoadRequestInsights();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error importing request.");
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Demostrates how to make a Multi-route optimization Request.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OptimizeItineraryBtn_Clicked(object sender, RoutedEventArgs e)
        {
            var r = new OptimizeItineraryRequest()
            {
                Agents = new List <Agent>()
                {
                    new Agent()
                    {
                        Name   = "agent1",
                        Shifts = new List <Shift>()
                        {
                            new Shift()
                            {
                                StartTimeUtc  = new DateTime(2022, 1, 1, 8, 0, 0),  //8 am
                                StartLocation = new SimpleWaypoint("1603 NW 89th St, Seattle, WA 98117, US"),
                                EndTimeUtc    = new DateTime(2022, 1, 1, 18, 0, 0), //6pm
                                EndLocation   = new SimpleWaypoint(47.7070790545669, -122.355226696231),
                                Breaks        = new Break[]
                                {
                                    new Break()
                                    {
                                        StartTimeUtc     = new DateTime(2022, 1, 1, 12, 0, 0), //12pm/noon
                                        EndTimeUtc       = new DateTime(2022, 1, 1, 14, 0, 0), //2pm
                                        DurationTimeSpan = new TimeSpan(0, 30, 0)              //30 minutes.
                                    },
                                    new Break()
                                    {
                                        StartTimeUtc = new DateTime(2022, 1, 1, 16, 0, 0), //4pm
                                        EndTimeUtc   = new DateTime(2022, 1, 1, 16, 30, 0) //4:30pm
                                    }
                                }
                            }
                        },
                        Price = new Price()
                        {
                            FixedPrice   = 100,
                            PricePerHour = 5,
                            PricePerKM   = 1
                        },
                        Capacity = new int[] { 16 }
                    }
                },
                ItineraryItems = new List <OptimizeItineraryItem>()
                {
                    new OptimizeItineraryItem()
                    {
                        Name           = "Customer 1",
                        OpeningTimeUtc = new DateTime(2022, 1, 1, 9, 0, 0),  //9am
                        ClosingTimeUtc = new DateTime(2022, 1, 1, 18, 0, 0), //6pm
                        DwellTimeSpan  = new TimeSpan(0, 32, 0),             //32 minutes
                        Priority       = 5,
                        Quantity       = new int[] { 4 },
                        //Waypoint = new SimpleWaypoint(47.692290770423,-122.385954752402),
                        Waypoint = new SimpleWaypoint("8712 Jones Pl NW, Seattle, WA 98117, US")
                    },
                    new OptimizeItineraryItem()
                    {
                        Name           = "Customer 2",
                        OpeningTimeUtc = new DateTime(2022, 1, 1, 9, 0, 0),  //9am
                        ClosingTimeUtc = new DateTime(2022, 1, 1, 18, 0, 0), //6pm
                        DwellTimeSpan  = new TimeSpan(1, 34, 0),             //1 hour 34 minutes
                        Priority       = 16,
                        Quantity       = new int[] { -3 },
                        Waypoint       = new SimpleWaypoint(47.6962193175262, -122.342180147243),
                        DropOffFrom    = new string[] { "Customer 3" }
                    },
                    new OptimizeItineraryItem()
                    {
                        Name           = "Customer 3",
                        OpeningTimeUtc = new DateTime(2022, 1, 1, 9, 0, 0),  //9am
                        ClosingTimeUtc = new DateTime(2022, 1, 1, 18, 0, 0), //6pm
                        DwellTimeSpan  = new TimeSpan(1, 0, 0),              //1 hour
                        Priority       = 88,
                        Quantity       = new int[] { 3 },
                        Waypoint       = new SimpleWaypoint(47.6798098928389, -122.383036445391)
                    },
                    new OptimizeItineraryItem()
                    {
                        Name           = "Customer 4",
                        OpeningTimeUtc = new DateTime(2022, 1, 1, 9, 0, 0),  //9am
                        ClosingTimeUtc = new DateTime(2022, 1, 1, 18, 0, 0), //6pm
                        DwellTimeSpan  = new TimeSpan(0, 25, 0),             //25 minutes
                        Priority       = 3,
                        Quantity       = new int[] { -3 },
                        Waypoint       = new SimpleWaypoint(47.6867440824094, -122.354711700877),
                        DropOffFrom    = new string[] { "Customer 1" }
                    },
                    new OptimizeItineraryItem()
                    {
                        Name           = "Customer 5",
                        OpeningTimeUtc = new DateTime(2022, 1, 1, 9, 0, 0),  //9am
                        ClosingTimeUtc = new DateTime(2022, 1, 1, 18, 0, 0), //6pm
                        DwellTimeSpan  = new TimeSpan(0, 18, 0),             //18 minutes
                        Priority       = 1,
                        Quantity       = new int[] { -1 },
                        Waypoint       = new SimpleWaypoint(47.6846639223203, -122.364839942855),
                        DropOffFrom    = new string[] { "Customer 1" }
                    }
                },
                BingMapsKey = BingMapsKey
            };

            ProcessRequest(r);
        }