Use a removable side-loading bean cartridge. The bottom of the cartridge would be mesh, the top open. There would be a spring-loaded door on the side of the cartridge that the machine would open once inserted (or it could be opened via a "lock" lever for a pure mechanical solution) so that beans could flow out. This way it could never be loaded with water, and the beans would stay fresh since once inserted the cartridge would be sealed on top and bottom by the rest of the machine.