First off,get the exam.Some of the brands of med will sicken/kill your dog if there are heartworms present when you give them the preventative.AS IN DEAD PUP,GOT IT?
Now,start asking around.There are a lot of sympathetic vet techs out there,especially in the rescue circuit.Some of them have the job of clearing out the meds that are being replaced by "new and improved" versions,or just a brand switch.Some of them are appaled by the waste of throwing out perfectly good meds into the trash.Some of them might even miss the trashcan when they throw out a sealed package of heartworm meds ,and it lands in a dry spot by the dumpster.
Luck!