public Order ProcessTheOrder(PreprocessedOrder order, Func <Transport, Order> getOrderByTransport)
        {
            List <Transport> currentTransports = order.SuitableTransport;

            List <DateTime> timesOfDelivery = new List <DateTime>();

            Dictionary <DateTime, Transport> dateTransportDictionary = new Dictionary <DateTime, Transport>();

            Transport selectedTransport = order.SuitableTransport.FindAll(transport => transport.InTheShop).ToList().ElementAt(0);

            double timeNeededForDelivery = 0;

            double dist = order.Destination.Distance;

            double speed = selectedTransport.Speed;

            timeNeededForDelivery = dist / speed;

            //timeNeededForDelivery =  Convert.ToDouble(destination.Distance)  / Convert.ToDouble(selectedTransport.Speed);

            timeNeededForDelivery = order.Product.TimeForPreparation + timeNeededForDelivery;

            //selectedTransport.InTheShop = false;

            Order newOrder = new Order(order.Destination, selectedTransport, order.Product, DateTime.Now, timeNeededForDelivery);

            return(newOrder);
        }
Beispiel #2
0
        public Order ProcessTheOrder(PreprocessedOrder order, Func <Transport, Order> getOrderByTransport)
        {
            List <Transport> currentTransports = order.SuitableTransport;

            List <DateTime> timesOfDelivery = new List <DateTime>();


            Dictionary <DateTime, Transport> dateTransportDictionary = new Dictionary <DateTime, Transport>();

            currentTransports.ForEach(transport => dateTransportDictionary.Add(getOrderByTransport(transport).TimeOfOrdering.AddSeconds(getOrderByTransport(transport).TimeNeededForDelivery), transport));

            List <DateTime> keysList = dateTransportDictionary.Keys.ToList();

            keysList.Sort((date1, date2) => date1.CompareTo(date2));

            DateTime theLeastTime = keysList.ElementAt(0);

            double timeNeededForDelivry = theLeastTime.Subtract(DateTime.Now).TotalSeconds + order.Destination.Distance / dateTransportDictionary[theLeastTime].Speed + order.Product.TimeForPreparation + getOrderByTransport(dateTransportDictionary[theLeastTime]).Destination.Distance / dateTransportDictionary[theLeastTime].Speed;

            Order newOrder = new Order(order.Destination, dateTransportDictionary[theLeastTime], order.Product, DateTime.Now, timeNeededForDelivry);

            return(newOrder);
        }