public long dropoffAfterPickup()

in prototype/dispatch/order-dispatcher/src/main/java/com/aws/proto/dispatching/domain/planningentity/v1/PlanningVisit.java [172:237]


    public long dropoffAfterPickup() {
        long PENALTY = 10L;

        if (previousVisitOrDriver == null) {
            throw new IllegalStateException("Must not be called when the previousVisitOrDriver is not initialized yet");
        }

        // previous item in the chain is the Driver (root of the chain)
        // --> this one is the first item in the chain
//        boolean isFirstVisitInChain = this.isFirstVisitInChain();
//
//
//        // first item in the chain cannot be CustomerVisit, since that's a dropoff
//        // --> PENALIZE
//        if(isFirstVisitInChain) {
//            if (this.location.getLocationType() == LocationType.CUSTOMER) {
//                return PENALTY;
//            } else {
//                return 0L;
//            }
//        }
//
//        if(this.getPlanningDriver().getShortId().equalsIgnoreCase("b550e4c3") && this.chainLength() > 3) {
//            logger.debug(this.printChain());
//        }

        String orderId = this.getOrder().getOrderId();
        // current visit is at Customer
        // --> must find Restaurant visit up the chain -- same orderId
        // --> must NOT find Restaurant visit down the chain -- same orderId
        if(this.location.getLocationType() == LocationType.CUSTOMER) {
            boolean hasRestaurantVisitWithSameOrderIdBefore = this.walkChainToAnchor(
              visit -> visit.getOrder().getOrderId().equalsIgnoreCase(orderId),
              visit -> visit.getLocation().getLocationType() == LocationType.RESTAURANT
            );

            boolean hasRestaurantVisitWithSameOrderIdAfter = this.walkChainToLeaf(
              visit -> visit.getOrder().getOrderId().equalsIgnoreCase(orderId),
              visit -> visit.getLocation().getLocationType() == LocationType.RESTAURANT
            );

            if(!hasRestaurantVisitWithSameOrderIdBefore || hasRestaurantVisitWithSameOrderIdAfter) {
                return PENALTY;
            }
        }
        // current visit is Restaurant
        // --> must NOT find Customer visit up the chain -- same orderId
        // --> must find Customer visit down the chain -- same orderId
        else {
            boolean notHaveCustomerVisitWithSameOrderIdBefore = this.walkChainToAnchor(
              visit -> visit.getOrder().getOrderId().equalsIgnoreCase(orderId),
              visit -> visit.getLocation().getLocationType() == LocationType.CUSTOMER
            );

            boolean notHaveCustomerVisitWithSameOrderIdAfter = this.walkChainToLeaf(
              visit -> visit.getOrder().getOrderId().equalsIgnoreCase(orderId),
              visit -> visit.getLocation().getLocationType() == LocationType.CUSTOMER
            );

            if(!notHaveCustomerVisitWithSameOrderIdBefore || notHaveCustomerVisitWithSameOrderIdAfter) {
                return PENALTY;
            }
        }

        return 0L;
    }