@phaedrux thanks! I think I figured out a solution: if I read the G-code documentation correctly, the firmware is aware of the currently loaded filament and triggering the unload macro is using the correct macro from the respective filament folder.
https://duet3d.dozuki.com/Wiki/Gcode#Section_M702_Unload_filament
That way I can have a load macro for PLA, PETG and TPU in the first 3 slots and an universal unload macro in the fourth.