public AvailableCar getAvailableCars(CarRequestModel request) { int minDistanceValue = int.MaxValue; List <AvailableCar> cars = new List <AvailableCar>(); lstCars.ForEach(c => { if (c.isBooked == false && c.bookedBy == "") { int distance_car_to_customer = distanceManager.calculateDistance(c.currentPosition, request.customerPosition); int customer_to_destination = distanceManager.calculateDistance(request.customerPosition, request.destination); int distance = distance_car_to_customer + customer_to_destination; if (distance <= minDistanceValue) { minDistanceValue = distance; int time = timeManager.calculateTime(distance); AvailableCar availableCar = new AvailableCar(c.id, time); cars.Add(availableCar); } } }); cars = cars.OrderBy(c => c.total_time).ToList(); return(cars.FirstOrDefault()); }