Max distance constraint on two consecutive activities of a route

I want to limit the distance between two consecutive activities of a route (except start and end) . I implemented a HardActivityConstraint but it’s not working as expected. It removes the routes that don’t violate this constraint.
Would you please help me?

    public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
        double maxDistanceOfConsecutiveActivities = #someValue;
        if (prevAct instanceof Start && nextAct instanceof End) {
            return ConstraintsStatus.FULFILLED;
        if (prevAct instanceof Start && getDistance(newAct.getLocation(), nextAct.getLocation()) <= maxDistanceOfConsecutiveActivities) {
            return ConstraintsStatus.FULFILLED;
        } else if (nextAct instanceof End && getDistance(newAct.getLocation(), prevAct.getLocation()) <= maxDistanceOfConsecutiveActivities) {
            return ConstraintsStatus.FULFILLED;
        if (getDistance(newAct.getLocation(), prevAct.getLocation()) > maxDistanceOfConsecutiveActivities
        || getDistance(newAct.getLocation(), nextAct.getLocation()) > maxDistanceOfConsecutiveActivities) {
            return ConstraintsStatus.NOT_FULFILLED;
        } else {
            return ConstraintsStatus.FULFILLED;

@Mohammad_Baghban you are doing just one thing wrong, You are calculating distance from new to previous but you need to calculate distance from prev to new activity.
So replace
getDistance(newAct.getLocation(), prevAct.getLocation())
this on both the occurrences with
getDistance(prevAct.getLocation(), newAct.getLocation())
then your hard constraint should work fine.