DAO Filtering

Estimated time to read: 1 minute

    // As above, however, this is extended as multiple filters can be used! Though this will need refactoring at some point so that it can be made more extensible
    List<Courier> filteredCouriers = courierDAOCSVImpl.getAllCouriers()
                                                       .stream()
                                                       .filter((courier) -> courier.getMaxDeliveryDistance() >= orderRequirements.getDeliveryDistance())
                                                       .filter((courier) -> { // courier is the current item from the list / the list within the array of type list. 
                                                            if (orderRequirements.isRefrigerationRequired()) { // If orderRequirements.isRefrigerationRequired true
                                                                return courier.getRefrigerationCapability(); // Return the item in the list that has getRefrigerationCapability set to true
                                                            } else {
                                                                return true; // If no refrigeration is required, return true to the Predicate... in other words, return all the 'courier' items in the list
                                                            }
                                                        })
                                                        .filter((courier) -> {
                                                            if(!orderRequirements.getShippingTime().isBefore(courier.getStartTime()) && orderRequirements.getShippingTime().isAfter(courier.getEndTime())) {
                                                                return false;
                                                            } else {
                                                                return true;
                                                            }
                                                       })
                                                       .collect(Collectors.toList());