Metal detector for foodstuffs with automatic ejection