first of all you should do a group by date, then a group by ID, then you will have to create the below formula in your ID group header to initialize your counter variable
WhilePrintingRecords;
Global numberVar record;
record:=0;
then place in your details this other formula
WhilePrintingRecords;
global numbervar record;
record:=(record+1);
record;
this formula will help you counting details record in order to suppress your details. then in your details section expert you will put the following Mailings.DELIVERED <> 0 or record > 5(this will suppress your detail section when the mailing was delivered or when you have more than 5 records )