Razvan,
I must assume that you don't fully understand expert Raghavendran's response. His method is the method commonly used to solve your business requirement, and it is SAP standard. In V_V2, all confirmations would be re-ordered so that the earliest delivery dates confirm against available supplies, and later delivery dates become partially or fully unconfirmed.
If you insist on using your personal logic to solve this business requirement, then it will require one or more enhancements. Spec it out and hand it off to your developers.
Best Regards,
DB49