Filter on date range

I have 3 attributes ordertype(enumeration), startdate and end date for Orders entity in the domain model. I want to place a condition where for a specific order type when a new entry is made the date range should not overlap the existing dates. For example :  OrderType      StartDate   EndDate     1                    02/02/20    07/02/20     2                    05/02/20    09/02/20  -----accepted     1                    04/02/20    08/09/20-------not accepted     1                   08/02/20     15/02/20------------accepted      1                   10/02/20     14/02/20 --------not accepted       2                  08/02/20     10/02/20 --------not accepted      1                   18/02/20      22/02/20 ------- accepted   if dateentered >= startdate and dateentered <= enddate  then date is not accepted.. I want to check for every entry of that order type. Can you please help how can this be done???
1 answers

Your StartDate as well as your EndDate are not allowed to be in the date range. And there should be no existing date range where one of the dates is bigger than your start date and smaller than your enddate.

Use an xpath like this:

[(StartDate < $NewStartDate and EndDate > $NewStartDate) or (StartDate < $NewEndDate and EndDate > $NewEndDate) or (StartDate > $NewStartDate and EndDate < $NewEndDate)]
[OrderType = $NewOrderType]

Count the result. If the Count is larger than 0, you have a violation.